package com.palm.hubo2o.view;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.ColorInt;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by wongqi on 16/6/22.
 */
public class SimpleListDecoration extends RecyclerView.ItemDecoration {
    //    private final int dividerColor;
    private final int dividerHeight;
    private final Paint paint;

    public SimpleListDecoration(@ColorInt int color, int height) {
//        dividerColor = color;
        dividerHeight = height;
        paint = new Paint();
        paint.setColor(color);
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        final int childCount = parent.getChildCount();
        if (childCount == 0)
            return;

        for (int i = 0; i < childCount - 1; i++) {
            final View child = parent.getChildAt(i);
            final int left = child.getLeft();
            final int right = child.getRight();
            final int top = child.getBottom();
            final int bottom = top + dividerHeight;
            c.drawRect(left, top, right, bottom, paint);
        }
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.set(0, 0, 0, dividerHeight);
    }
}
